<template>
	<view class="login-container">
		<view class="login-form">
			<view class="login-title">
				账号登录
			</view>
			<u--form errorType="message" labelPosition="left" :model="loginForm" :borderBottom="false"
				ref="loginFormRef" :rules="loginRules">
				<u-form-item prop="username" style="box-shadow: ;">
					<u--input clearable border="false" shape="circle" v-model="loginForm.username"
						placeholder="请输入您的用户名">
					</u--input>
				</u-form-item>
				<u-form-item prop="password">
					<u--input type="password" clearable border="false" placeholderStyle="color: #999FAD;" shape="circle"
						v-model="loginForm.password" placeholder="请输入登录密码"></u--input>
				</u-form-item>
			</u--form>
			<!-- 忘记密码 -->
			<view class="forget-password">
				<view class="left">
					<text class="c-theme-clor">忘记密码</text>
				</view>
				<view class="right">
					没有账号,立即<navigator class="c-theme-clor" url="../register/register">注册</navigator>
				</view>
			</view>
			<!-- 登录按钮 -->
			<view class="login-btn c-theme-btn-b" @click="loginUser">
				登录
			</view>
		</view>
	</view>
</template>
<script>
	import {
		login
	} from "@/api/login.js"
	import {
		TOAST
	} from "@/utils/utils.js"
	export default {
		data() {
			return {
				loginForm: {
					username: "zhangruoqi",
					password: "1234567"
				},
				loginRules: {
					username: [{
						required: true,
						message: '请输入用户名',
						trigger: ['blur', 'change']
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: ['blur', 'change']
					}]
				}
			}
		},
		methods: {
			loginUser() {
				this.$refs.loginFormRef.validate().then(res => {
					login({
						username: this.loginForm.username,
						password: this.loginForm.password
					}).then(res => {
						if (res.code === 200) {
							TOAST("登录成功")
							uni.setStorageSync("userInfo",res.data)
							uni.setStorageSync("token",res.data.token)
							setTimeout(() => {
								uni.switchTab({
									url: "../index/index"
								})
							}, 1000)
						}
					}).catch(err => {
						console.log(err)
					})
				})

			}
		}
	}
</script>
<style lang="scss" scoped>
	.login-container {
		height: 100%;
		overflow-y: auto;
		padding: 0 80rpx;
		display: flex;
		align-items: center;

		.login-form {
			width: 100%;

			.login-title {
				font-size: 52rpx;
				color: #3F7BED;
				font-weight: 800;
			}

			.u-form {
				margin-top: 200rpx;
			}
		}

		.forget-password {
			display: flex;
			align-items: center;
			justify-content: space-between;
			margin-top: 20rpx;
			padding: 0 20rpx;

			.right {
				display: flex;
			}
		}

		.login-btn {
			margin-top: 80rpx;
			width: 100%;
			border: 1px solid #FFFFFF;
			border-radius: 40rpx 40rpx 40rpx 40rpx;
			background-color: #3F7BED;
			line-height: 100rpx;
			text-align: center;
			color: #FFFFFF;
		}
	}
</style>
